﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Camc.Quality.QualityPlatform
{
    public class EnumTransfer
    {
        /// <summary>
        /// 根据传入的int返回对应枚举属性名称
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string GetEnumName<T>(int value)
        {
            string name = "";
            name = Enum.Parse(typeof(T), Enum.GetName(typeof(T), value)).ToString();
            return name;
        }
        /// <summary>
        /// 根据传入的枚举属性获得对应值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int GetEnumValue<T>(string value)
        {
            Type type = typeof(T);
            var schoolId = Enum.Format(type, Enum.Parse(type, value.ToUpper()), "d");
            return Convert.ToInt32(schoolId);
        }
        /// <summary>
        /// 枚举转化示例
        /// </summary>
        public void Examples()
        {
            //string Name = GetEnumName<ActionType>(1);  // 根据传入的属性值返回对应枚举属性名称
            //int value = GetEnumValue<ActionType>("Open");  // 根据传入的属性名称获得对应值
            //int value1 = (int)ActionType.OPEN;  // 直接使用枚举类指定属性值
        }
    }
}
